package luzhin;

import java.io.*;
import java.util.Arrays;
/**
 * Attack diagram. Can check checks.
 * Created with AttackDiagramBuilder objects.
 * @author lacungus
 *
 */
public class AttackDiagram implements Serializable {
	private int[] whiteAttacks;
	private int[] blackAttacks;
	private boolean isSafe;
	private boolean isCheckToWhite;
	private boolean isCheckToBlack;
	
	private static final long serialVersionUID = 223434564435L;
	
	/**
	 * Builds attack diagram on the parameters.
	 * @param whiteAttacks
	 * @param blackAttacks
	 * @param isSafe
	 * @param isCheckToWhite
	 * @param isCheckToBlack
	 */
	AttackDiagram(int[] whiteAttacks, int[] blackAttacks, boolean isSafe, boolean isCheckToWhite, boolean isCheckToBlack) {
		this.whiteAttacks = whiteAttacks;
		this.blackAttacks = blackAttacks;
		this.isSafe = isSafe;
		this.isCheckToWhite = isCheckToWhite;
		this.isCheckToBlack = isCheckToBlack;
	}
	
	/**
	 * 
	 * @return White attacks.
	 */
	public int[] getWhiteAttacks() {
		return whiteAttacks; 
	}

	/**
	 * 
	 * @return Black attacks.
	 */
	public int[] getBlackAttacks() {
		return blackAttacks; 
	}
	
	/**
	 * Checking board for the safety.
	 * @return
	 */
	public boolean isSafe() {
		return isSafe;
	}
	
	/**
	 * @return
	 */
	public boolean isCheckToWhite() {
		return isCheckToWhite;
	}

	/**
	 * @return
	 */
	public boolean isCheckToBlack() {
		return isCheckToBlack;
	}

    @Override
    public boolean equals(Object o) {
        AttackDiagram ad = (AttackDiagram) o;
        if (!isSafe == ad.isSafe)
            return false;
        if (!isCheckToWhite == ad.isCheckToWhite)
            return false;
        if (!isCheckToBlack == ad.isCheckToBlack)
            return false;
        return Arrays.equals(whiteAttacks, ad.whiteAttacks) && Arrays.equals(blackAttacks, ad.blackAttacks);
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 83 * hash + Arrays.hashCode(this.whiteAttacks);
        hash = 83 * hash + Arrays.hashCode(this.blackAttacks);
        hash = 83 * hash + (this.isSafe ? 1 : 0);
        hash = 83 * hash + (this.isCheckToWhite ? 1 : 0);
        hash = 83 * hash + (this.isCheckToBlack ? 1 : 0);
        return hash;
    }
}
